﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http.Controllers;

using Newtonsoft.Json;

using ProjectBase.Core;

using $prjsn$.Common;

namespace $safeprojectname$
{
    public class EntityConfigurationAttribute : Attribute, IControllerConfiguration
    {
        public virtual void Initialize(HttpControllerSettings settings, HttpControllerDescriptor descriptor)
        {
            SetFormatter(settings);
        }

        protected virtual void SetFormatter(HttpControllerSettings settings)
        {
            // Remove the JSON formatter.
            var jsonFormatter = settings.Formatters.JsonFormatter;
            settings.Formatters.Remove(jsonFormatter);

            // new Formatter instance
            var jFormatter = new JsonpFormatter
            {
                Indent = Project.Settings.UseJsonIndent,
            };

            settings.Formatters.Add(jFormatter);
            jFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
        }
    }
}
